﻿using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using Zhouyu.DreamTour.WinService.Job;
using ZhouYu.DreamTour.Core;
using ZhouYu.DreamTour.DAL.IRepository;
using ZhouYu.DreamTour.WinService.Common;
using ZhouYu.DreamTour.WinService.Job;

namespace Zhouyu.DreamTour.WinService
{
    public partial class Service1 : ServiceBase
    {
        public readonly string trigroup = "servicetrigroup";
        public readonly string trigGroupName = "servicetrigGroupName";

        
        public Service1()
        {
            InitializeComponent();
        }

        protected async override void OnStart(string[] args)
        {
            //实例化调度程序
            ISchedulerFactory sf = new StdSchedulerFactory();
            IScheduler _sched = await sf.GetScheduler();
            //获取所有任务
            List<string> list = ConfigurationHelper.GetSectionKeyList("Crons");

            //判断任务集合中是否包含备份数据库任务
            if (list.Contains(JobType.examineJob))
            {
                JobschedulerManager.AddScheduler<ExamineJob>(ref _sched, JobType.examineJob, trigroup, trigGroupName);
            }
            //判断任务集合中是否包含旅游团购支付任务
            if (list.Contains(JobType.touristrouteJob))
            {
                File.AppendAllText("D:\\Log.txt", "支付任务");
                JobschedulerManager.AddScheduler<TouristRouteJob>(ref _sched, JobType.touristrouteJob, trigroup, trigGroupName);
            }

            //执行
            await _sched.Start();
        }

        protected override void OnStop()
        {
        }
    }
}
